﻿using System.Web.Mvc;
using Moq;
using NUnit.Framework;
using Tamias.BasicCmsPortableArea.Areas.CmsAdmin.Controllers;
using Tamias.BasicCmsPortableArea.Areas.CmsAdmin.ViewModels.ContentItem;
using Tamias.BasicCmsPortableArea.Domain;
using System.Collections.Generic;

namespace Tamias.UnitTests.ControllerTests
{
    [TestFixture]
    public class ContentItemControllerTests
    {
        [Test]
        public void List_ValidId_ReturnsViewWithList()
        {
            const int groupId = 1;

            var itemServiceStub = new Mock<IContentItemService>();
            itemServiceStub.Setup(stub => stub.GetList(groupId))
                .Returns(new List<ContentItem>()
                {
                    new ContentItem { Id = 1, Name = "Foo" },
                    new ContentItem { Id = 2, Name = "Bar" }
                });

            var ctrl = new ContentItemController();
            ctrl.ContentItemService = itemServiceStub.Object;
            
            var result = ctrl.List(1) as ViewResult;
            Assert.IsNotNull(result, "Expected a ViewResult.");

            var vm = result.ViewData.Model as ListViewModel;
            vm.Items.Count.IsEqualTo(2, "Expected two items.");
        }
    }
}
